"""
Case Type   : Compatibility
Case Name   : 验证逻辑操作符的bool值输出(and/or/not)
Create At   : 2024/10/18
Owner       : liu-tong-8848
Description :
              1.and操作符
              2.or操作符
              3.not操作符
              4.混合使用
Expect      :
              1.成功
              2.成功
              3.成功
              4.成功
History     :
"""

import os
import unittest

from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger
from yat.test import Node


class SQL(unittest.TestCase):
    def setUp(self):
        self.log = Logger()
        self.Constant = Constant()
        self.primary_sh = CommonSH('PrimaryDbBmode')
        self.db_user_node = Node(node='PrimaryDbBmode')

    def test_add_dimension(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        step1 = '--step1：and操作符 expect：执行成功'
        self.log.info(step1)
        sql = "select true and 0 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step1)
        sql = "select false and false as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step1)
        sql = "select 1 and 1 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step1)

        step2 = ' --step2：or操作符 expect：执行成功'
        self.log.info(step2)
        sql = "select 1 or 0 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step2)
        sql = "select true or 1 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step2)
        sql = "select false or 0 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step2)

        step3 = '--step3：not操作符 expect：执行成功'
        self.log.info(step3)
        sql = "select not 1 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("f", result, "执行失败" + step3)
        sql = "select not false as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step3)

        step4 = '--step4：混合使用 expect：执行成功'
        self.log.info(step4)
        sql = "select 1 and(true or (not false)) or 0 as c;"
        self.log.info(sql)
        result = self.primary_sh.execut_db_sql(sql)
        self.log.info(result)
        self.assertIn("t", result, "执行失败" + step4)

    def tearDown(self):
        self.log.info(f'-----{os.path.basename(__file__)} end-----')
